package test.netty.io.echo;

import java.util.concurrent.Executors;

import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;

public class EchoClient {

	/**
	 * @uml.property  name="host"
	 */
	private final String host; 
	/**
	 * @uml.property  name="port"
	 */
	private final int port; 
	/**
	 * @uml.property  name="firstMessageSize"
	 */
	private final int firstMessageSize; 
	
	public EchoClient(String host, int port, int firstMessageSize){
		this.port=port;
		this.host=host; 
		this.firstMessageSize= firstMessageSize; 
	}
	
	public void run(){
		ClientBootstrap bootstrap = new ClientBootstrap(
					new NioClientSocketChannelFactory(
							Executors.newCachedThreadPool(),
							Executors.newCachedThreadPool()));
		// pipeline factory create
		bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
			
			@Override
			public ChannelPipeline getPipeline() throws Exception {
				return Channels.pipeline( new EchoClientHandler(firstMessageSize));
			}
		});
		
	}
	
}
